import { ETaskState } from "GameLoop/DecisionMaking/TaskDeclare/type";
import { ATaskAdapter } from ".";
import { RoomTaskChecker } from "../TaskCheck/RoomTaskChecker";

export class RoomTaskAdapter extends ATaskAdapter<"room">
{
    constructor(context:IContextGetter,world:WorldGetter)
    {
        super(context,world);
        RoomTaskChecker.notify = this.notify.bind(this);
    }
 
    public bindTasks(room: Room, tasks:ITaskDeclare["room"][],customCheck:IConditionFunction): void 
    {
        for(const task of tasks)
        {
            if(customCheck(room as Required<Room>,task) == OK )
            {
                room.deleteTaskById(task.id,"room");
                continue;
            }
            if(ETaskState.Complete == this.checkState(room,task))
            {
                //global.Log.Info(`${room.name} room ${task.id} check 已经完成`);
                room.log("info","任务完成",JSON.stringify(task));
                room.deleteTaskById(task.id,"room");
                continue;
            }
           // global.Log.Info(`${room.name} room ${task.id} check 未完成`);
        }
    }

    protected checkState(room:Room,task:ITaskDeclare["room"]):ETaskState
    {
        return RoomTaskChecker.check(room,task);
      
    }
    
}